package com.gwcloud.leetcode.hot100;

import com.gwcloud.leetcode.common.datastructure.TreeNode;

/** 
* @ClassName   : Leetcode0236 
* @author      : ganwei 
* @date        : 2020年5月22日 
* @Description : 236. 二叉树的最近公共祖先 
*/
public class Leetcode0236 {
	/**
	 * -解题思路，递归解决
	 */
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
    	if(root == null || root == p || root == q){
    		return root;
    	}
    	TreeNode left = lowestCommonAncestor(root.left, p, q);
    	TreeNode right = lowestCommonAncestor(root.right, p, q);
    	if(left == null){
    		return right;
    	}
    	if(right == null){
    		return left;
    	}
        return root;
    }
    
    public static void main(String[] args) {
    	
    }
}
